﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NPS_app_MasterData_ActivityName :PageBase
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           if (getMode == FormMode.Editor)
            {
                loadData();
                btnSave.Text = "Update";
                lblHeader.Text = "Master Data: Activity Name Edit";
            }
        }
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities.NPSMarketingName MarketingName = new Entities.NPSMarketingName()
        {
            sxTitle =setStringSecurity(txtName.Text),
            sxDetail = setStringSecurity(txtDetail.Text)
        };
        if (getMode == FormMode.Editor)
        {
            MarketingName.sxUpdater = ICPUser.ID;
            MarketingName.iID = getItemID;
            updateMarketingName(MarketingName);
        }
        else { saveMarketingName(MarketingName); }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {

    }

    #endregion

    #region Audy's Custom Function
    protected void loadData()
    {
        //fetch data from DB
        Controller.NPSMarketingNameController ANController = new Controller.NPSMarketingNameController();
        Entities.NPSMarketingName MarketingName = ANController.getNPSMarketingName(getItemID);

        //set all data to forms
        txtName.Text = MarketingName.sxTitle;
        txtDetail.Text = MarketingName.sxDetail;
    }

    protected bool saveMarketingName(Entities.NPSMarketingName MarketingName)
    {
        Controller.NPSMarketingNameController ANController = new Controller.NPSMarketingNameController();
        if (ANController.InsertNPSMarketingNameData(MarketingName) == 0)
        { return false; }
        else { return true; }
    }

    protected void updateMarketingName(Entities.NPSMarketingName MarketingName)
    {
        Controller.NPSMarketingNameController ANController = new Controller.NPSMarketingNameController();
        ANController.UpdateNPSMarketingNameData(MarketingName);
    }
    #endregion 
}
